from pynumpak.type import func_t, Interval
from .romberg import romberg


def inner_product(f: func_t, g: func_t, ab: Interval, rho: func_t = None):
    if rho is None:
        return romberg(lambda x: f(x) * g(x), ab)
    else:
        return romberg(lambda x: f(x) * g(x) * rho(x), ab)


def mse(f: func_t, g: func_t, ab: Interval, rho: func_t = None):
    return inner_product(lambda x: f(x) - g(x), lambda x: f(x) - g(x), ab=ab, rho=rho)
